import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'privacy_policy_text.dart';

// 隐私政策文本 带 复选框
class PrivacyPolicyWithCheckbox extends StatelessWidget {
  final String normalText;
  // 替换标识
  final String replaceFlag;
  final RxBool isChecked;
  final String? highlightText;
  final String? privacyPolicyText;
  final String? userAgreementText;
  final TextStyle? normalStyle;
  final TextStyle? highlightStyle;
  final TextStyle? linkStyle;
  final double? textTopPadding;
  final VoidCallback? onPrivacyPolicyTap;
  final VoidCallback? onUserAgreementTap;
  final Function(bool)? onChanged;
  final Image? selectedImage;
  final Image? unselectedImage;
  final Color? checkBoxActiveColor;
  final Color? checkBoxCheckColor;
  final MaterialTapTargetSize? materialTapTargetSize;
  final VisualDensity? visualDensity;
  final bool isTextClickable;

  const PrivacyPolicyWithCheckbox({
    Key? key,
    required this.isChecked,
    required this.normalText,
    required this.selectedImage,
    required this.unselectedImage,
    required this.replaceFlag,
    this.highlightText,
    this.privacyPolicyText,
    this.userAgreementText,
    this.normalStyle,
    this.highlightStyle,
    this.linkStyle,
    this.onPrivacyPolicyTap,
    this.onUserAgreementTap,
    this.textTopPadding,
    this.onChanged,
    this.checkBoxActiveColor,
    this.checkBoxCheckColor,
    this.materialTapTargetSize,
    this.visualDensity,
    this.isTextClickable = true,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        GestureDetector(
          onTap: () {
            if (onChanged != null) {
              onChanged!(isChecked.value);
            }
          },
          child: selectedImage == null || unselectedImage == null
              ? Obx(
                  () => Checkbox(
                    value: isChecked.value,
                    onChanged: (value) {
                      if (onChanged != null) {
                        onChanged!(isChecked.value);
                      }
                    },
                    activeColor: checkBoxActiveColor ??
                        Theme.of(context).colorScheme.primary,
                    checkColor: checkBoxCheckColor ?? Colors.white,
                    materialTapTargetSize: materialTapTargetSize,
                    visualDensity: visualDensity,
                  ),
                )
              : Obx(() => SizedBox(
                    width: 24,
                    height: 24,
                    child: isChecked.value ? selectedImage : unselectedImage,
                  )),
        ),
        Expanded(
          child: GestureDetector(
            onTap: isTextClickable
                ? () {
                    if (onChanged != null) {
                      onChanged!(isChecked.value);
                    }
                  }
                : null,
            child: Padding(
              padding: EdgeInsets.only(top: textTopPadding ?? 4),
              child: PrivacyPolicyText(
                normalText: normalText,
                replaceFlag: replaceFlag,
                highlightText: highlightText,
                privacyPolicyText: privacyPolicyText,
                userAgreementText: userAgreementText,
                normalStyle: normalStyle,
                highlightStyle: highlightStyle,
                linkStyle: linkStyle,
                onPrivacyPolicyTap: onPrivacyPolicyTap,
                onUserAgreementTap: onUserAgreementTap,
              ),
            ),
          ),
        ),
      ],
    );
  }
}
